"""FAQ API Router"""
from typing import List
from typing_extensions import Annotated

from fastapi import APIRouter, Depends, Path, Query

from api.v1.service.faq import FaqServiceAPI
from api.v1.models.faq import FaqMasterResponse, FaqResponse
from api.v1.models.response import response_404, response_422

router = APIRouter()


@router.get("/faqs",
            summary="FAQ 分类列表查询")
async def read_faqs(
    service: Annotated[FaqServiceAPI, Depends()],
) -> List[FaqMasterResponse]:
    """查看常见问题分类列表。
"""
    return service.read_faq_masters()


@router.get("/faqs/{fm_id}",
            summary="FAQ 分类 > 内容查询列表",
            responses={**response_404, **response_422})
async def read_faq(
    service: Annotated[FaqServiceAPI, Depends()],
    fm_id: Annotated[int, Path(title="FAQ 分类Idi",
                               description="FAQ 分类Idi")],
    stx: str = Query(None, title="搜索词", description="搜索词")
) -> List[FaqResponse]:
    # “查看分类中的常见问题解答内容列表。”

    faq_master = service.read_faq_master(fm_id)

    return service.read_faqs(faq_master, stx)
